home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / SCHMOO.ZIP / OLEMISC.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  5KB  |  204 lines

  1. /*
  2.  * OLEMISC.C
  3.  *
  4.  * Functions without another approprate home:
  5.  *  MenuEmbeddingSet
  6.  *  OLEClientNotify
  7.  *  FOLEReleaseWait
  8.  *
  9.  *
  10.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  11.  *
  12.  */
  13.  
  14. #ifdef MAKEOLESERVER
  15.  
  16. #include <windows.h>
  17. #include <ole.h>
  18. #include "schmoo.h"
  19. #include "oleglobl.h"
  20.  
  21.  
  22.  
  23. /*
  24.  * MenuEmbeddingSet
  25.  *
  26.  * Purpose:
  27.  *  Modifies the main menu of the application to change "Save" to "Update"
  28.  *  and to change "Exit" to "Exit & return to xx."  Alternately, this
  29.  *  function can change the menus back to the original state, reverting
  30.  *  "Update" to "Save" and setting the Exit item back to plain "Exit."
  31.  *
  32.  * Parameters:
  33.  *  hWnd            HWND of the window with the menu.
  34.  *  pszClient       LPSTR to the client name.
  35.  *  fOLE            BOOL indiciating if we are to set for OLE or to normal.
  36.  *                  If setting to normal, pszClient can be NULL.
  37.  *
  38.  * Return Value:
  39.  *  None.
  40.  *
  41.  */
  42.  
  43. void FAR PASCAL MenuEmbeddingSet(HWND hWnd, LPSTR pszClient, BOOL fOLE)
  44.     {
  45.     HMENU       hMenu;
  46.     char        szTemp[130];
  47.     LPSTR       pszT;
  48.  
  49.     hMenu=GetMenu(pGlob->hWnd);
  50.  
  51.     //Change the File/Save menu to File/Update <client> or vice-versa
  52.     if (fOLE)
  53.         wsprintf(szTemp, rgpsz[IDS_UPDATE], pszClient);
  54.     else
  55.         lstrcpy(szTemp, rgpsz[IDS_SAVE]);
  56.  
  57.     ModifyMenu(hMenu, IDM_FILESAVE, MF_STRING, IDM_FILESAVE, szTemp);
  58.  
  59.  
  60.     //Change the File/Save As menu to File/Save Copy As or vice-versa.
  61.     pszT=(fOLE) ? rgpsz[IDS_SAVECOPYAS] : rgpsz[IDS_SAVEAS];
  62.     ModifyMenu(hMenu, IDM_FILESAVEAS, MF_STRING, IDM_FILESAVEAS, pszT);
  63.  
  64.  
  65.     //Change "Exit" to "Exit & return to xx" or vice-versa.
  66.     if (fOLE)
  67.         wsprintf(szTemp, rgpsz[IDS_EXITANDRETURN], pszClient);
  68.     else
  69.         lstrcpy(szTemp, rgpsz[IDS_EXIT]);
  70.  
  71.     ModifyMenu(hMenu, IDM_FILEEXIT, MF_STRING, IDM_FILEEXIT, szTemp);
  72.     return;
  73.     }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. /*
  81.  * OLEClientNotify
  82.  *
  83.  * Purpose:
  84.  *  Performs a direct function call to the single callback in the
  85.  *  client that is communicating with this server application.
  86.  *  This is the only point where there is direct communication
  87.  *  between the two applciations.
  88.  *
  89.  * Parameters:
  90.  *  pObj            LPSCHMOOOBJECT that contains a pClient pointer to an
  91.  *                  LPOLECLIENT that holds a pointer to the OLECLIENTVTBL
  92.  *                  that holds a pointer to the CallBack function.
  93.  *  wMsg            WORD, message to send, such as OLE_CLOSED.
  94.  *
  95.  * Return Value:
  96.  *  None.
  97.  */
  98.  
  99. void FAR PASCAL OLEClientNotify(LPSCHMOOOBJECT pObj, WORD wMsg)
  100.     {
  101.     LPOLECLIENT     pClient;
  102.     LPOLECLIENTVTBL pvt;
  103.  
  104.     if (NULL==pObj)
  105.         return;
  106.  
  107.     pClient=pObj->pClient;
  108.  
  109.     if (NULL==pClient)
  110.         return;
  111.  
  112.     pvt=pClient->lpvtbl;
  113.  
  114.     if (NULL==pvt)
  115.         return;
  116.  
  117.     (pvt->CallBack)(pClient, wMsg, (LPOLEOBJECT)pObj);
  118.     return;
  119.     }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. /*
  127.  * FOLEReleaseWait
  128.  *
  129.  * Purpose:
  130.  *  Enters a Peek/Translate/Dispatch message loop to process all messages
  131.  *  to the application until a release flag has been sent.  The application
  132.  *  calls this routine whenever it is required to wait until conversations
  133.  *  for OLE have terminated.
  134.  *
  135.  *  Some of the messages processed may be DDE messages (for OLE 1.x) that
  136.  *  are eventually passed to OLESVR which eventually calls the ServerRelease
  137.  *  function (see OLESVR.C).  ServerRelease modifies a BOOL flag indicating
  138.  *  that the server is released.
  139.  *
  140.  *  Therefore we can watch a particular memory location (*pf)
  141.  *  and only exit when that flag is set.
  142.  *
  143.  * Parameters:
  144.  *  pf              BOOL FAR * to the flag to wait on.
  145.  *  lhSvr           LHANDLE for the OLE server
  146.  *
  147.  * Return Value:
  148.  *  BOOL            Contents of *pf.
  149.  *
  150.  */
  151.  
  152. BOOL FAR PASCAL FOLEReleaseWait(BOOL FAR *pf, LONG lhSvr)
  153.     {
  154.     MSG        msg;
  155.  
  156.     *pf=FALSE;
  157.  
  158.     while (FALSE==*pf)
  159.         {
  160.         /*
  161.          * We use PeekMessage here to make a point about power
  162.          * management and ROM Windows--GetMessage, when there's
  163.          * no more messages, will correctly let the system go into
  164.          * a low-power idle state.  PeekMessage by itself will not.
  165.          * If you do background processing in a PeekMessage loop like
  166.          * this, and there's no background processing to be done,
  167.          * then you MUST call WaitMessage to duplicate the idle
  168.          * state like GetMessage.
  169.          */
  170.  
  171.         if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  172.             {
  173.             /*
  174.              * We will not see WM_QUIT in the middle of the
  175.              * application since this application MUST call
  176.              * PostQuitMessage to get it in the queue.  Therefore we
  177.              * don't even worry about it.
  178.              */
  179.  
  180.             TranslateMessage (&msg);
  181.             DispatchMessage (&msg);
  182.             }
  183.         else
  184.             {
  185.             /*
  186.              * If the application has some background processing
  187.              * to do, it should perform a piece of it here.  Otherwise
  188.              * you MUST call WaitMessage or you'll screw up ROM-Windows
  189.              * power-management.
  190.              */
  191.  
  192.             WaitMessage();
  193.             }
  194.         }
  195.  
  196.     return *pf;
  197.     }
  198.  
  199.  
  200.  
  201.  
  202.  
  203. #endif //MAKEOLESERVER
  204.